package com.example.prison.mapper;

import com.example.prison.entity.VisitorDeviceInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【visitor_device_info】的数据库操作Mapper
* @createDate 2024-06-03 15:01:14
* @Entity com.example.prison.entity.VisitorDeviceInfo
*/
@Mapper
public interface VisitorDeviceInfoMapper extends BaseMapper<VisitorDeviceInfo> {

    @Select("<script>select * from visitor_device_info " +
            " <where> " +
            " <if test=\"deviceNumber != null and deviceNumber != ''\">and device_number like concat('%',#{deviceNumber},'%') </if> " +
            " </where> " +
            "order by device_id desc</script>")
    List<VisitorDeviceInfo> get(@Param("deviceNumber") String deviceNumber);

    @Insert("insert into visitor_device_info(type,device_name, device_number, device_area, is_use, device_status, access) " +
            "values (#{type},#{deviceName}, #{deviceNumber}, #{deviceArea}, #{isUse}, #{deviceStatus}, #{access})")
    int add(VisitorDeviceInfo vDevice);

    @Delete("<script>delete from visitor_device_info where device_id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleting(@Param("ids") Integer[] ids);

//    @Update("update visitor_device_info set device_name=#{vDevice.deviceName},device_number=#{vDevice.deviceNumber}," +
//            "device_area=#{vDevice.deviceArea},is_use=#{vDevice.isUse},device_status=#{vDevice.deviceStatus},access=#{vDevice.access} " +
//            "where device_id = #{deviceId}")
    @Update({"<script> UPDATE visitor_device_info",
            "<set>",
            "<if test='vDevice.deviceName != null'>device_name = #{vDevice.deviceName},</if>",
            "<if test='vDevice.deviceNumber != null'>device_number = #{vDevice.deviceNumber},</if>",
            "<if test='vDevice.deviceArea != null'>device_area = #{vDevice.deviceArea},</if>",
            "<if test='vDevice.isUse != null'>is_use = #{vDevice.isUse},</if>",
            "<if test='vDevice.deviceStatus != null'>device_status = #{vDevice.deviceStatus},</if>",
            "<if test='vDevice.access != null'>access = #{vDevice.access},</if>",
            "</set>",
            "where device_id = #{deviceId} </script>"})
    int updating(VisitorDeviceInfo vDevice,Integer deviceId);

    @Select("select * from visitor_device_info where device_id=#{deviceId}")
    VisitorDeviceInfo getById(@Param("deviceId") Integer deviceId);

    @Select("select * from visitor_device_info where device_number=#{deviceNumber} order by device_id desc")
    VisitorDeviceInfo getOneByNumber(@Param("deviceNumber") String deviceNumber);

    @Select("select * from visitor_device_info where device_number=#{deviceNumber} order by device_id desc")
    List<VisitorDeviceInfo> getListOneByNumber(@Param("deviceNumber") String deviceNumber);

}




